package com.wu.leetcode.leetcode78;

import java.util.ArrayList;
import java.util.List;

/**
 * Leetcode78-子集
 *
 * @author lynn
 * @date 2020/8/18 - 17:56
 */
class Solution {
    public static List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        if (nums == null || nums.length == 0) {
            return null;
        }
        dfs(nums, 0, res, new ArrayList<Integer>());
        return res;
    }

    private static void dfs(int[] nums, int index, List<List<Integer>> res, ArrayList<Integer> list) {
        if (index == nums.length) {
            res.add(new ArrayList<>(list));
            return;
        }
        list.add(nums[index]);
        dfs(nums, index + 1, res, list);
        list.remove(list.size() - 1);
        dfs(nums, index + 1, res, list);
    }

    public static void main(String[] args) {
        int[] arr = new int[]{1, 2, 3};
        List<List<Integer>> subsets = subsets(arr);
    }
}
